function showLoginForm() {
    if (document.getElementById('login-user').checked) {
        // display login form 1
        document.getElementById('login-form-user').style.display = 'grid';
        document.getElementById('login-form-visitor').style.display = 'none';
    } else {
        // display login form 2
        document.getElementById('login-form-user').style.display = 'none';
        document.getElementById('login-form-visitor').style.display = 'grid';
    }
}

document.addEventListener("DOMContentLoaded", function () {
    const loginForm = document.getElementById("login-form-user");

    loginForm.addEventListener("submit", function (e) {
        e.preventDefault(); // 阻止默认的表单提交行为
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;

        // 构建请求体
        const requestBody = {
            account: username,
            password: password
        };

        // 发送POST请求到后端
        fetch('/home/map', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(requestBody)
        })
            .then(response => response.json())
            .then(response => {
                console.log(response)
                if (response.status === 200) {
                    // 登录成功
                    localStorage.clear();
                    window.location.href = '../html/index.html';
                    return response.text();
                } else {

                }
            })
            .then(data => {
                console.log(data); // 处理成功登录的响应
            })
            .catch(error => {
                console.error(error); // 处理登录失败或其他错误
            });

    });
});





document.addEventListener("DOMContentLoaded", function () {
    const loginForm = document.getElementById("login-form-visitor");

   loginForm.addEventListener("submit", function (e) {
        e.preventDefault(); // 阻止默认的表单提交行为
        localStorage.setItem('userType','visitor')
        window.location.href = '../html/index.html';
    });
});
